<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>激活</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<link rel="stylesheet" type="text/css" href="${csspath }/datepicker.css" />
<link rel="stylesheet" type="text/css" href="${csspath }/style_l.css" />
<script type="text/javascript" src="${jspath }/jquery/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${layerPath}/layer.js"></script>
<script type="text/javascript" src="${jspath }/jquery.ui.min.js"></script>
<script type="text/javascript" src="${jspath }/ui.datepicker_zh-CN.js"></script>
<script type="text/javascript" src="${jspath }/jquery.blockUI.js"></script>
<script type="text/javascript" src="${jspath }/public.js"></script>
<script type="text/javascript" src="${jspath }/jquery.selectAll.js"></script>
<script type="text/javascript"
	src="${jspath}/jquery/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.alerts.js"></script>
<link rel="stylesheet" type="text/css"
	href="${csspath}/jquery.alerts.css" />
<script type="text/javascript" src="${jspath}/load_layer.js"></script>
<link rel="stylesheet" type="text/css"
	href="${webcontext}/css/validationEngine.jquery.css" />
<script src="${jspath}/jquery/validate/jquery.validationEngine.js"
	type="text/javascript"></script>
<script src="${jspath}/jquery/validate/jquery.validationEngine-zh.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="${webcontext}/javascript/jquery/jquery.ui.draggable.js"></script>
<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<style type="text/css">
.formError .formErrorContent {
	-moz-border-radius: 6px 6px 6px 6px;
	-moz-box-shadow: 0 0 6px #000000;
	background: none repeat scroll 0 0 #EE0101;
	border: 2px solid #DDDDDD;
	color: #FFFFFF;
	font-family: tahoma;
	font-size: 11px;
	padding: 4px 10px;
	width: 100px;
}
</style>
<script type="text/javascript">
	$(function() {

		$("#cancel")
				.click(
						function() {
							jConfirm(
									"取消激活操作？",
									"确认提示",
									function(result) {
										if (result == true) {
											if ('${dto.fromPurchasePage}' == 'true') {
												window.location.href = "${webcontext}/crmdp/dealer/purchase/toMemberPurchase?mobilePhone="
														+ '${dto.mobilePhone}'
														+ "&id="
														+ '${dto.memberId}'
														+ "&carPlate="
														+ encodeURI(encodeURI('${dto.carPlate}'))
														+ "&memberName="
														+ encodeURI(encodeURI('${dto.memberName}'))
														+ "&packageNumber="
														+ encodeURI(encodeURI('${dto.packageNumber}'))
														+ "&packageDefId="
														+ '${dto.packageDefId}';
											} else {
												window.location.href = "${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
											}
										}
									});
						});

		$("#saveAndSubmit")
				.click(
						function() {
							if ($("#packageNumber").val() == "") {
								jAlert("卡号不能为空！");
								return;
							}
							if ($("#packageActiveCode").val() == "") {
								jAlert("验证码不能为空！");
								return;
							}

							jConfirm(
									"确认激活？",
									"确认提示",
									function(result) {
										if (result == true) {
											if ('${dto.fromPurchasePage}' == 'true') {
												$
														.ajax({
															url : '${webcontext}/crmdp/dealer/activation/toSaveMemberActivation?fromPurchasePage=true',
															type : 'post',
															data : $('form')
																	.serialize(),
															beforeSend : function() {
																layer.load(1);
															},
															success : function(
																	data) {
																layer
																		.closeAll('loading');
																if (data.errorMsg != null) {
																	jAlert("操作失败！"
																			+ data.errorMsg);
																} else {
																		jAlert(
																				data.successMsg,
																				"提示信息",
																				function() {
																					window.location.href = "${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
																				})
																}
															},
															error : function(
																	msg) {
																alert("请求失败！"
																		+ msg);
															}
														})

											} else {
												$
														.ajax({
															url : '${webcontext}/crmdp/dealer/activation/toSaveMemberActivation',
															type : 'post',
															data : $('form')
																	.serialize(),
															beforeSend : function() {
																layer.load(1);
															},
															success : function(
																	data) {
																layer
																		.closeAll('loading');
																if (data.errorMsg != null) {
																	jAlert("操作失败！"
																			+ data.errorMsg);
																} else {
																		jAlert(
																				data.successMsg,
																				"提示信息",
																				function() {
																					window.location.href = "${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
																				})
																}
															},
															error : function(
																	msg) {
																alert(msg);
															}
														})
												/* $("#activate").submit(); */
											}
										}
									});

						});

	});

	function idCardValid(value) {
		var strP = /^(\d{15}|(\d{17}[\dXx]))$/;
		if (strP.test(value)) {
			return true;
		} else {
			return false;
		}
	}

	function showDetail() {
		if ($("#packageNumber").val() == "") {
			jAlert("卡号不能为空！");
			return;
		}
		$
				.ajax({
					url : '${webcontext}/crmdp/dealer/activation/isPackageNumberExist',
					type : 'post',
					data : $('form').serialize(),
					success : function(data) {
						if (!data.success) {
							jAlert(data.error);
						} else {
							//iframe层
							layer
									.open({
										type : 2,
										title : '详细信息',
										shadeClose : false,
										closeBtn : false,
										shade : 0.1,
										offset : [ '10%', '25%' ],
										area : [ '500px', '380px' ],
										content : "${webcontext}/crmdp/dealer/activation/toPurchaseDetailInfo?packageNumber="
												+ $("#packageNumber").val(),//iframe的url
										end : function() {
											//关闭弹出层后回调方法
										}
									});
						}
					}
				});

	}
	
	$(function(){
		$("#packageActiveCode").on("keypress", function(event){
			if(13 == event.keyCode){
				return false;
			}
			
		});
	});
</script>



</head>
<body>
	<div id="content">
		<!-- wrap -->
		<div id="wrap">
			<form:form id="activate"
				action="#"
				method="post" modelAttribute="dto" enctype="multipart/form-data">
				<form:input type="hidden" path="memberId" name="id" />
				<form:input type="hidden" path="packageDefId" name="packageDefId" />
				<form:input type="hidden" path="onhandQuantity" />
				<form:input type="hidden" path="price" />
				<input type="hidden" id="operationType" name="operationType" />
				<div class="input_div">
					<div class="title">
						<p>激活</p>
					</div>
					<div>
						<style>
.input_tab {
	table-layout: fixed;
}
</style>
						<div class="spliter h_10"></div>
						<div class="spliter h_5"></div>
						<table class="input_tab">
							<tr>
								<td width="10%" align="right">手机：</td>
								<td width="20%"><form:input type="hidden"
										path="mobilePhone" cssClass="text" readonly="true" />${dto.mobilePhone}</td>
								<td width="10%" align="right">姓名：</td>
								<td width="20%" align="left"><form:input type="hidden"
										path="memberName" cssClass="text string" readonly="true" />${dto.memberName}</td>
								<td width="10%" align="right">车牌：</td>
								<td width="10%" align="left"><form:input type="hidden"
										id="carPlate" path="carPlate" cssClass="text" readonly="true" />${dto.carPlate}</td>
								<core:if test="${!empty dto.packageDefId}">
									<td width="10%" align="right">套餐名称：</td>
									<td width="20%" align="left">${dto.packageName}</td>
								</core:if>
								<core:if test="${empty dto.packageDefId}">
									<td width="10%" class="label" align="right"></td>
									<td width="20%" align="left"></td>
								</core:if>

							</tr>
							<tr>
								<td align="right">卡号：</td>
								<td align="left">
									<div style="float: left">
										<core:if test="${empty dto.packageDefId}">
											<form:input path="packageNumber" id="packageNumber"
												cssClass="form-control input-sm validate[required] text string" />
										</core:if>
										<core:if test="${!empty dto.packageDefId}">
										<input type="hidden" name="packageNumber" value="${dto.packageNumber}" />
	                     	   			${dto.packageNumber}
	                      	   	 </core:if>
									</div> <core:if
										test="${dto.packageDefId==null or dto.packageDefId==''}">
										<div style="float: left">
											&nbsp;&nbsp;
											<button type="button"
												class="btn btn-success btn-xs btnLength"
												style="width: 60px;" onClick="showDetail()">查看详情</button>
										</div>
									</core:if>
								</td>
								<td align="right"><!-- <span class="need">*</span> -->验证码：</td>
								<td align="left"><form:input path="packageActiveCode"
										id="packageActiveCode"
										cssClass="form-control input-sm validate[required] text" /></td>
								<td colspan="2" class="error">${dto.errorMsg}</td>
								<td class="label" align="right"></td>
								<td align="left"></td>
							</tr>
						</table>
						<div class="spliter h_10"></div>
						<div class="spliter h_5"></div>
					</div>
				</div>
				<!-- /info_div -->

				<div class="spliter h_10"></div>
				<div class="spliter h_5"></div>

				<div class="btn_div">
					<button type="button" class="btn" style="width: 100px;"
						id="saveAndSubmit" value="激活">
						<i class="glyphicon glyphicon-ok-sign" style="color: #FFFFFF"></i>&nbsp;激活
					</button>
					<button type="button" class="btn" style="width: 100px;" value="取消"
						id="cancel">
						<i class="glyphicon glyphicon-share-alt" style="color: #FFFFFF"></i>&nbsp;取消
					</button>
				</div>

			</form:form>
		</div>
		<!-- /wrap -->
	</div>
	<!-- /content -->

</body>

</html>